home *** CD-ROM | disk | FTP | other *** search
- package sunw.demo.buttons;
-
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.awt.event.MouseMotionListener;
- import java.beans.PropertyChangeListener;
- import java.beans.PropertyChangeSupport;
- import java.io.Serializable;
- import java.util.Vector;
-
- public class OurButton extends Component implements Serializable, MouseListener, MouseMotionListener {
- private boolean debug;
- private PropertyChangeSupport changes;
- private Vector pushListeners;
- private String label;
- private boolean down;
- private boolean sized;
- static final int TEXT_XPAD = 12;
- static final int TEXT_YPAD = 8;
-
- public OurButton() {
- this("press");
- }
-
- public OurButton(String var1) {
- this.changes = new PropertyChangeSupport(this);
- this.pushListeners = new Vector();
- this.label = var1;
- this.setFont(new Font("Dialog", 0, 12));
- this.setBackground(Color.lightGray);
- ((Component)this).addMouseListener(this);
- ((Component)this).addMouseMotionListener(this);
- }
-
- public synchronized void paint(Graphics var1) {
- int var2 = ((Component)this).getSize().width;
- int var3 = ((Component)this).getSize().height;
- var1.setColor(((Component)this).getBackground());
- var1.fill3DRect(0, 0, var2 - 1, var3 - 1, !this.down);
- var1.setColor(((Component)this).getForeground());
- var1.setFont(((Component)this).getFont());
- var1.drawRect(2, 2, var2 - 4, var3 - 4);
- FontMetrics var4 = var1.getFontMetrics();
- var1.drawString(this.label, (var2 - var4.stringWidth(this.label)) / 2, (var3 + var4.getMaxAscent() - var4.getMaxDescent()) / 2);
- }
-
- public void mouseClicked(MouseEvent var1) {
- }
-
- public void mousePressed(MouseEvent var1) {
- if (((Component)this).isEnabled()) {
- this.down = true;
- ((Component)this).repaint();
- }
- }
-
- public void mouseReleased(MouseEvent var1) {
- if (((Component)this).isEnabled()) {
- if (this.down) {
- this.fireAction();
- this.down = false;
- ((Component)this).repaint();
- }
-
- }
- }
-
- public void mouseEntered(MouseEvent var1) {
- }
-
- public void mouseExited(MouseEvent var1) {
- }
-
- public void mouseDragged(MouseEvent var1) {
- if (((Component)this).isEnabled()) {
- int var2 = var1.getX();
- int var3 = var1.getY();
- int var4 = ((Component)this).getSize().width;
- int var5 = ((Component)this).getSize().height;
- if (var2 >= 0 && var2 <= var4 && var3 >= 0 && var3 <= var5) {
- if (!this.down) {
- this.down = true;
- ((Component)this).repaint();
- }
- } else if (this.down) {
- this.down = false;
- ((Component)this).repaint();
- return;
- }
-
- }
- }
-
- public void mouseMoved(MouseEvent var1) {
- }
-
- public synchronized void addActionListener(ActionListener var1) {
- this.pushListeners.addElement(var1);
- }
-
- public synchronized void removeActionListener(ActionListener var1) {
- this.pushListeners.removeElement(var1);
- }
-
- public void addPropertyChangeListener(PropertyChangeListener var1) {
- this.changes.addPropertyChangeListener(var1);
- }
-
- public void removePropertyChangeListener(PropertyChangeListener var1) {
- this.changes.removePropertyChangeListener(var1);
- }
-
- public void fireAction() {
- if (this.debug) {
- System.err.println("Button " + this.getLabel() + " pressed.");
- }
-
- synchronized(this){}
-
- Vector var1;
- try {
- var1 = (Vector)this.pushListeners.clone();
- } catch (Throwable var6) {
- throw var6;
- }
-
- ActionEvent var2 = new ActionEvent(this, 0, (String)null);
-
- for(int var3 = 0; var3 < var1.size(); ++var3) {
- ActionListener var4 = (ActionListener)var1.elementAt(var3);
- var4.actionPerformed(var2);
- }
-
- }
-
- public void setDebug(boolean var1) {
- boolean var2 = this.debug;
- this.debug = var1;
- this.changes.firePropertyChange("debug", new Boolean(var2), new Boolean(var1));
- }
-
- public boolean getDebug() {
- return this.debug;
- }
-
- public void setLargeFont(boolean var1) {
- if (this.isLargeFont() != var1) {
- byte var2 = 12;
- if (var1) {
- var2 = 18;
- }
-
- Font var3 = ((Component)this).getFont();
- this.setFont(new Font(var3.getName(), var3.getStyle(), var2));
- this.changes.firePropertyChange("largeFont", new Boolean(!var1), new Boolean(var1));
- }
- }
-
- public boolean isLargeFont() {
- return ((Component)this).getFont().getSize() >= 18;
- }
-
- public void setFontSize(int var1) {
- Font var2 = ((Component)this).getFont();
- this.setFont(new Font(var2.getName(), var2.getStyle(), var1));
- this.changes.firePropertyChange("fontSize", new Integer(var2.getSize()), new Integer(var1));
- }
-
- public int getFontSize() {
- return ((Component)this).getFont().getSize();
- }
-
- public void setFont(Font var1) {
- Font var2 = ((Component)this).getFont();
- super.setFont(var1);
- this.sizeToFit();
- this.changes.firePropertyChange("font", var2, var1);
- }
-
- public void setLabel(String var1) {
- String var2 = this.label;
- this.label = var1;
- this.sizeToFit();
- this.changes.firePropertyChange("label", var2, var1);
- }
-
- public String getLabel() {
- return this.label;
- }
-
- public Dimension getPreferredSize() {
- FontMetrics var1 = ((Component)this).getFontMetrics(((Component)this).getFont());
- return new Dimension(var1.stringWidth(this.label) + 12, var1.getMaxAscent() + var1.getMaxDescent() + 8);
- }
-
- /** @deprecated */
- public Dimension preferredSize() {
- return this.getPreferredSize();
- }
-
- public Dimension getMinimumSize() {
- return this.getPreferredSize();
- }
-
- /** @deprecated */
- public Dimension minimumSize() {
- return this.getMinimumSize();
- }
-
- private void sizeToFit() {
- Dimension var1 = this.getPreferredSize();
- ((Component)this).setSize(var1.width, var1.height);
- Container var2 = ((Component)this).getParent();
- if (var2 != null) {
- ((Component)var2).invalidate();
- ((Component)var2).doLayout();
- }
-
- }
-
- public void setForeground(Color var1) {
- Color var2 = ((Component)this).getForeground();
- super.setForeground(var1);
- this.changes.firePropertyChange("foreground", var2, var1);
- ((Component)this).repaint();
- }
-
- public void setBackground(Color var1) {
- Color var2 = ((Component)this).getBackground();
- super.setBackground(var1);
- this.changes.firePropertyChange("background", var2, var1);
- ((Component)this).repaint();
- }
- }
-